<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Test</title>
  </head>
  <body>
    <div>
      <h2>测试用网页</h2>
      <button>点我</button>
      <button id="pickerPhoto">相册服务mk.pickerPhoto</button>
      <button id="pickerCamera">拍照服务 mk.pickerCamera</button>
      <button id="vibrator">传感器 mk.vibrator</button>
      <button id="getAreaColumns">地址 mk.getAreaColumns</button>
      <br /><br />
      <img style="width: 100px" src="" alt="" />
      <p></p>
    </div>
    <script>
      const button = document.querySelector("button");
      button.addEventListener("click", () => {
        // mk.sayHi("测试一下注入的sayHI方法");
        console.log(window.mk);
        const userinfo = mk.queryUser();
        document.querySelector("h2").innerText = JSON.stringify(userinfo);
        // mk.removeUser();
      });
      // 相册服务
      const pickerPhoto = document.querySelector("#pickerPhoto");
      pickerPhoto.addEventListener("click", async () => {
        const str = await mk.pickerPhoto();
        console.log(str);
        // 显示base64图片,需要添加前缀标识，否则图片无法标识
        document.querySelector("img").src = `data:image/jpeg;base64,${str}`;
      });
      // 拍照服务
      const pickerCamera = document.querySelector("#pickerCamera");
      pickerCamera.addEventListener("click", async () => {
        const str = await mk.pickerCamera();
        console.log(str);
        // 显示base64图片,需要添加前缀标识，否则图片无法标识
        document.querySelector("img").src = `data:image/jpeg;base64,${str}`;
      });
      // 传感器
      const vib = document.querySelector("#vibrator");
      vib.addEventListener("click", async () => {
        const str = await mk.vibrator();
        console.log(str);
      });
      // 获取地址服务
      const getAreaColumns = document.querySelector("#getAreaColumns");
      getAreaColumns.addEventListener("click", async () => {
        const str = await mk.getAreaColumns();
        console.log(str);
      });
    </script>
    <script src="./eruda.min.js"></script>
    <script>
      eruda.init();
    </script>
  </body>
</html>
